package com.tongqu.controller;

import com.tongqu.annotation.RequestMapping;
import com.tongqu.po.Request;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;
import org.springframework.stereotype.Controller;

import static io.netty.buffer.Unpooled.copiedBuffer;

@Controller
public class ErrorController {

    @RequestMapping(path = "/error404")
    public void error404(ChannelHandlerContext channelHandlerContext, Request request) {
        FullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
                HttpResponseStatus.OK,
                copiedBuffer("404错误，路径找不到", CharsetUtil.UTF_8));
        resp.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
        channelHandlerContext.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
    }
}
